home *** CD-ROM | disk | FTP | other *** search
/ Oxygen Multimedia Graphics 22 / Oxygen Multimedia Graphics 22.iso / pc / System / OX22 / Internal_48_Sprite Track Mouse.ls < prev    next >
Encoding:
Text File  |  2008-03-12  |  2.7 KB  |  106 lines

  1. property pSprite, pStageBounds, pCentered, pLimited
  2.  
  3. on getBehaviorDescription me
  4.   return "SPRITE TRACK MOUSE" & RETURN & RETURN & "This behavior will move a sprite so that it is under the cursor. " & "The sprite will appear with its registration point or center under the cursor's hotspot." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Graphic members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Center sprite on cursor" & RETURN & "* Limited to stage area"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Makes a sprite move to follow the cursor around the stage so that the center of the sprite is under the cursor."
  9. end
  10.  
  11. on beginSprite me
  12.   mInitialize(me)
  13. end
  14.  
  15. on prepareFrame me
  16.   mUpdate(me)
  17. end
  18.  
  19. on mCenter vRect
  20.   vHalfWidth = vRect.width / 2
  21.   vHalfHeight = vRect.height / 2
  22.   return point(vRect.left + vHalfWidth, vRect.top + vHalfHeight)
  23. end
  24.  
  25. on mCenterOffset
  26.   vCenter = mCenter(sprite(pSprite).rect)
  27.   return vCenter - sprite(pSprite).loc
  28. end
  29.  
  30. on mCenteredRect vPoint, vRect
  31.   vWidth = vRect.width
  32.   vHeight = vRect.height
  33.   vHalfWidth = vWidth / 2
  34.   vHalfHeight = vHeight / 2
  35.   vLeft = vPoint.locH - vHalfWidth
  36.   vTop = vPoint.locV - vHalfHeight
  37.   return rect(vLeft, vTop, vLeft + vWidth, vTop + vHeight)
  38. end
  39.  
  40. on mInitialize me
  41.   pSprite = me.spriteNum
  42.   pStageBounds = point((the stage).rect.width, (the stage).rect.height)
  43. end
  44.  
  45. on mStageLimit vRect
  46.   if vRect.left < 0 then
  47.     vOffsetH = -vRect.left
  48.   else
  49.     vOffsetH = min(0, pStageBounds.locH - vRect.right)
  50.   end if
  51.   if vRect.top < 0 then
  52.     vOffsetV = -vRect.top
  53.   else
  54.     vOffsetV = min(0, pStageBounds.locV - vRect.bottom)
  55.   end if
  56.   return offset(vRect, vOffsetH, vOffsetV)
  57. end
  58.  
  59. on mUpdate me
  60.   if pCentered then
  61.     vRect = mCenteredRect(the mouseLoc, sprite(pSprite).rect)
  62.   else
  63.     vRect = mCenteredRect(the mouseLoc + mCenterOffset(), sprite(pSprite).rect)
  64.   end if
  65.   if pLimited then
  66.     vRect = mStageLimit(vRect)
  67.   end if
  68.   sprite(pSprite).rect = vRect
  69. end
  70.  
  71. on mSetCentered me, vBool
  72.   if not (not vBool) = vBool then
  73.     pCentered = vBool
  74.   end if
  75. end
  76.  
  77. on mSetLimited me, vBool
  78.   if not (not vBool) = vBool then
  79.     pLimited = vBool
  80.   end if
  81. end
  82.  
  83. on mToggleCentered me
  84.   pCentered = not pCentered
  85. end
  86.  
  87. on mToggleLimited me
  88.   pLimited = not pLimited
  89. end
  90.  
  91. on isOKToAttach me, aSpriteType, aSpriteNum
  92.   case aSpriteType of
  93.     #graphic:
  94.       return getPos([#quickTimeMedia, #flash, #digitalVideo], sprite(aSpriteNum).member.type) = 0
  95.     #script:
  96.       return 0
  97.   end case
  98. end
  99.  
  100. on getPropertyDescriptionList
  101.   vPDList = [:]
  102.   setaProp(vPDList, #pCentered, [#comment: "Center sprite on cursor (alternative is to use loc)", #format: #boolean, #default: 1])
  103.   setaProp(vPDList, #pLimited, [#comment: "Limited to stage area", #format: #boolean, #default: 1])
  104.   return vPDList
  105. end
  106.